package com.vc.commons.db;

import javax.sql.DataSource;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import com.alibaba.druid.pool.DruidDataSource;

/**
 * 默认的数据源
 * @author Cris
 *
 */
@Component
public class DefaultDataSource {
	
	@Autowired
	private DruidDataSourceConfig druidDBConfig;
	
	/**
	 * 声明其为Bean实例 在同样的DataSource中，首先使用被标注的DataSource
	 * 
	 * @return
	 */
	@Bean
	@Primary
	public DataSource dataSource() {
		DruidDataSource datasource = null;

		datasource = new DruidDataSource();

		BeanUtils.copyProperties(druidDBConfig, datasource);
		
		/*datasource.setUrl(this.url);
		datasource.setUsername(username);
		datasource.setPassword(password);
		datasource.setDriverClassName(driverClassName);

		// configuration
		datasource.setInitialSize(initialSize);
		datasource.setMinIdle(minIdle);
		datasource.setMaxActive(maxActive);
		datasource.setMaxWait(maxWait);
		datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
		datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
		datasource.setValidationQuery(validationQuery);
		datasource.setTestWhileIdle(testWhileIdle);
		datasource.setTestOnBorrow(testOnBorrow);
		datasource.setTestOnReturn(testOnReturn);
		datasource.setPoolPreparedStatements(poolPreparedStatements);
		datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
		datasource.setFilters(filters);
		datasource.setConnectionProperties(connectionProperties);*/

		return datasource;
	}
}
